<template>
  <div v-loading="loading" class="wx">
    <div class="wx__img" />
    <div class="wx__title"><i class="el-icon-circle-check" />您已成功在企业微信中添加IBECRM</div>
    <el-button class="wx__btn" type="primary" @click="goLogin">去登录</el-button>
  </div>
</template>

<script>
import { wechatCpRegisterAPI } from '@/wechat/api'

export default {
  // 企业微信登录注册结果
  name: 'WechatLoginResult',

  components: {},

  props: {},

  data() {
    return {
      loading: false,
      isSuccess: false
    }
  },

  computed: {},

  watch: {},

  created() {},

  mounted() {
    if (!this.$route.query.auth_code) {
      this.$router.push({
        name: '/'
      })
      return
    }
    this.getPreAuth()
  },

  beforeDestroy() {},

  methods: {
    /**
     * 获取预授权码
     */
    getPreAuth() {
      if (this.$route.query.auth_code) {
        this.loading = true
        wechatCpRegisterAPI({
          authCode: this.$route.query.auth_code
        }).then(res => {
          this.isSuccess = true
          this.loading = false
        }).catch(() => {
          this.isSuccess = false
          this.loading = false
        })
      }
    },

    goLogin() {
      this.$router.replace({
        name: 'login'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.wx {
  text-align: center;
  background-color: #f4f9ff;

  &__img {
    display: block;
    width: 100%;
    height: 30vh;
    margin: 15vh auto 0;
    background: url("./wx_bg.png") no-repeat center;
    background-size: contain;
  }

  &__title {
    margin-top: 20px;
    font-size: 17px;

    .el-icon-circle-check {
      margin-right: 5px;
      color: $--color-primary;
    }
  }

  &__des {
    margin-top: 10px;
    font-size: 14px;
    color: #999;
  }

  &__btn {
    margin-top: 20px;
    margin-bottom: 30px;
  }
}
</style>
